<?php


namespace App\Form\Type;


use App\Enum\PageEnum;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PagePublishFieldType extends AbstractType {
    private $em;

    public function __construct (EntityManagerInterface $entityManager) {
        $this->em = $entityManager;
    }

    public function configureOptions (OptionsResolver $resolver) {
        parent::configureOptions($resolver); // TODO: Change the autogenerated stub
    }

    public function buildForm (FormBuilderInterface $builder, array $options) {
        parent::buildForm($builder, $options); // TODO: Change the autogenerated stub
    }

    public function buildView (FormView $view, FormInterface $form, array $options) {
        parent::buildView($view, $form, $options); // TODO: Change the autogenerated stub

        // 获取当前对象
        $object = $form->getParent()->getData();
        $view->vars['object'] = $object;

        $view->vars['publish_time_date'] = null;
        $view->vars['publish_time_time'] = null;
        if ($object->getPublishTime() && $object->getPublishType() == PageEnum::PUBLISH_TYPE_TIMING) {
            $view->vars['publish_time_date'] = $object->getPublishTime()->format('Y-m-d');
            $view->vars['publish_time_time'] = $object->getPublishTime()->format('H:i');
        }
    }
}